import { getGameInfo } from '~/pages/play/helpers';
import { TEST_CURRENCY } from '~/stores/currency';

export default defineRoute(() => [
  {
    path: '/sports',
    component: Layouts.default,
    redirect: { name: RN.SPORTS },
    children: [
      {
        path: ':gameCode',
        name: RN.SPORTS,
        props: true,
        component: () => import('./index.vue'),
        async beforeEnter(to, from) {
          const authed = useAuthed();
          if (!authed.value) {
            antdMessage.error($t('gy0QaFjSyErjUIcpWzxo0'));
            globalPopups.sign?.open?.();
            return from;
          }

          const cryptoName = localStorage.getItem('CRYPTO_NAME');
          if (!cryptoName) {
            return from;
          }
          if (cryptoName === TEST_CURRENCY) {
            antdMessage.error($t('yRs2TSbGkDq10wvgaY2m'));
            return from;
          }

          const gameCode = String(to.params.gameCode);
          const gameInfo = await getGameInfo(gameCode);

          return gameInfo ? gameInfo.sport : from;
        },
      },
    ],
  },
]);
